@section('meta')
    <style>
        body{background-color: #fff;}
        .modal-content{display: unset;}
        .layui-form-label {width: 100px;}
        .layui-input-block {margin-left: 138px;}
        .layui-input, .layui-textarea {width: 86%;}
        .layui-form-select .layui-edge {right: 16%;}
        .layui-form-select dl {min-width: 86%;}
        .new-table {margin: 20px 0;}
        .layui-input.layui-bg-gray {line-height: 38px;}

    </style>
@endsection
@include('Home.User.Common._meta')
<!----  新增： 兼职者  ---->
<div class="modal-content new-table" id="addNew-content2">
    <form class="layui-form modal-client-info" action="" id="form-user" lay-filter="form-user">
        @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->assign || Auth::id()==$obj->uid || $obj->share || !$obj->display)
            <div class="modal-func-btns">
                @if(!$obj->display)
                    <a href="javascript:;" class="modal-save-btn" onclick="buy('{{route('resume_buy',$obj->id)}}')" title="下载简历">下载简历</a>
                @endif
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->assign || Auth::id()==$obj->uid || $obj->share)
                    <a href="javascript:;" class="modal-save-btn" onclick="subForm('{{route('resume_edit',$obj->id)}}')" title="保存"><i class="icon icon-save"></i></a>
                    <a href="javascript:location.replace(location.href);" class="modal-edit-btn" title="重置"><i class="icon icon-edit"></i></a>
                @endif
                </div>
            @include('Home.User.Common._msg')
        @endif
        <div class="layui-form-item">
            <label class="layui-form-label">当前简历归属</label>
            <div class="layui-input-block">
                <div class="layui-input layui-bg-gray">{{$obj->assign_user?$obj->assign_user->username:''}}</div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>姓名</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <input type="text" name="name" lay-verify="required" placeholder="请输入姓名" value="{{$obj->name}}" autocomplete="off" class="layui-input">
                @else
                    <div class="layui-input layui-bg-gray">{{$obj->name}}</div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>国家区号</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <select name="country_code" id="country_code" lay-search>
                        <option value="0" disabled selected>请选择</option>
                        <option value="63" @if($obj->country_code == 63) selected @endif>菲律宾（+ 63）</option>
                        <option value="86" @if($obj->country_code == 86) selected @endif>中国大陆（+ 86）</option>
                        <option value="853" @if($obj->country_code == 853) selected @endif>澳门（+ 853）</option>
                        <option value="852" @if($obj->country_code == 852) selected @endif>香港（+ 852）</option>
                        <option value="886" @if($obj->country_code == 886) selected @endif>台湾（+ 886）</option>
                        <option value="60" @if($obj->country_code == 60) selected @endif>马来西亚（+ 60）</option>
                        <option value="66" @if($obj->country_code == 66) selected @endif>泰国（+ 66）</option>
                        <option value="65" @if($obj->country_code == 65) selected @endif>新加坡（+ 65）</option>
                        <option value="84" @if($obj->country_code == 84) selected @endif>越南（+ 84）</option>
                        <option value="95" @if($obj->country_code == 95) selected @endif>缅甸（+ 95）</option>
                        <option value="855" @if($obj->country_code == 855) selected @endif>柬埔寨（+ 855）</option>
                        <option value="856" @if($obj->country_code == 856) selected @endif>老挝（+ 856）</option>
                        <option value="62" @if($obj->country_code == 62) selected @endif>印度尼西亚（+ 62）</option>
                        <option value="350" @if($obj->country_code == 350) selected @endif>直布罗陀（+ 350）</option>
                        <option value="356" @if($obj->country_code == 356) selected @endif>马耳他（+ 356）</option>
                        <option value="58" @if($obj->country_code == 58) selected @endif>委内瑞拉（+ 58）</option>
                        <option value="504" @if($obj->country_code == 504) selected @endif>洪都拉斯（+ 504）</option>
                        <option value="505" @if($obj->country_code == 505) selected @endif>尼加拉瓜（+ 505）</option>
                        <option value="506" @if($obj->country_code == 506) selected @endif>哥斯达黎加（+ 506）</option>
                        <option value="61" @if($obj->country_code == 61) selected @endif>澳大利亚（+ 61）</option>
                    </select>
                @else
                    <div class="layui-input layui-bg-gray">{{$obj->country_code}}</div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>手机</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <input type="text" name="phone" lay-verify="required" placeholder="请输入手机" value="{{$obj->phone}}" autocomplete="off" class="layui-input">
                @else
                    @if($obj->display)
                        <div class="layui-input layui-bg-gray">{{$obj->phone}}</div>
                    @else
                        @if(Auth::user()->type != 1)
                            <div class="layui-input layui-bg-gray">********</div>
                        @else
                            <div class="layui-input layui-bg-gray"><a href="javascript:;" onclick="buy('{{route('resume_buy',$obj->id)}}')">********</a></div>
                        @endif
                    @endif
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>电子邮箱</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <input type="text" name="email" lay-verify="required" placeholder="请输入电子邮箱" value="{{$obj->email}}" autocomplete="off" class="layui-input">
                @else
                    @if($obj->display)
                        <div class="layui-input layui-bg-gray">{{$obj->email}}</div>
                    @else
                        @if(Auth::user()->type != 1)
                            <div class="layui-input layui-bg-gray">********</div>
                        @else
                            <div class="layui-input layui-bg-gray"><a href="javascript:;" onclick="buy('{{route('resume_buy',$obj->id)}}')">********</a></div>
                        @endif
                    @endif
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">微信</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <input type="text" name="wechat" lay-verify="required" placeholder="请输入微信" value="{{$obj->wechat}}" autocomplete="off" class="layui-input">
                @else
                    @if($obj->display)
                        <div class="layui-input layui-bg-gray">{{$obj->wechat}}</div>
                    @else
                        @if(Auth::user()->type != 1)
                            <div class="layui-input layui-bg-gray">********</div>
                        @else
                            <div class="layui-input layui-bg-gray"><a href="javascript:;" onclick="buy('{{route('resume_buy',$obj->id)}}')">********</a></div>
                        @endif
                    @endif
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>性别</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <input type="radio" name="sex" value="1" title="男" @if($obj->sex == 1) checked @endif>
                    <input type="radio" name="sex" value="2" title="女" @if($obj->sex == 2) checked @endif>
                    <input type="radio" name="sex" value="3" title="不详" @if($obj->sex == 3) checked @endif>
                @else
                    @if($obj->display)
                        <div class="layui-input layui-bg-gray">
                            @switch($obj->sex)
                                @case(1)
                                男
                                @break
                                @case(2)
                                女
                                @break
                                @case(3)
                                不详
                                @break
                                @default
                                不详
                            @endswitch
                        </div>
                    @else
                        @if(Auth::user()->type != 1)
                            <div class="layui-input layui-bg-gray">********</div>
                        @else
                            <div class="layui-input layui-bg-gray"><a href="javascript:;" onclick="buy('{{route('resume_buy',$obj->id)}}')">********</a></div>
                        @endif
                    @endif
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>出生年月</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <input type="text" name="birthday" id="birthday" lay-verify="required" placeholder="请输入出生年月" value="{{$obj->birthday}}" autocomplete="off" class="layui-input">
                @else
                    <div class="layui-input layui-bg-gray">{{$obj->birthday}}</div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>国籍</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <select id="nationality" name="nationality" lay-search>
                        <option value="0" disabled selected>请选择</option>
                        @foreach($country as $k => $v)
                            <option value="{{$k}}" @if($obj->nationality == $k) selected @endif>{{$v['name']}}</option>
                        @endforeach
                    </select>
                @else
                    <div class="layui-input layui-bg-gray">
                        @foreach($country as $k => $v)
                            @if($obj->nationality == $k)
                                {{$v['name']}}
                            @endif
                        @endforeach
                    </div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">现居地</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <input type="text" name="living" lay-verify="required" placeholder="请输入现居地" value="{{$obj->living}}" autocomplete="off" class="layui-input">
                @else
                    <div class="layui-input layui-bg-gray">{{$obj->living}}</div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>学历</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <select id="education" name="education">
                        <option value="0" disabled>请选择</option>
                        @foreach($education as $k => $v)
                            <option value="{{$k}}" @if($obj->education == $k) selected @endif>{{$v['name']}}</option>
                        @endforeach
                    </select>
                @else
                    <div class="layui-input layui-bg-gray">
                        @foreach($education as $k => $v)
                            @if($obj->education == $k)
                                {{$v['name']}}
                            @endif
                        @endforeach
                    </div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>工作经验</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <select id="experience" name="experience">
                        <option value="0" disabled>请选择</option>
                        @foreach($working_time as $k => $v)
                            <option value="{{$k}}" @if($obj->experience == $k) selected @endif>{{$v['name']}}</option>
                        @endforeach
                    </select>
                @else
                    <div class="layui-input layui-bg-gray">
                        @foreach($working_time as $k => $v)
                            @if($obj->experience == $k)
                                {{$v['name']}}
                            @endif
                        @endforeach
                    </div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>求职职位</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <select id="position" name="position" lay-search>
                        <option value="0" disabled>请选择</option>
                        @foreach($position_class as $parent1)
                            <optgroup label="{{$parent1->name}}">
                                @foreach($parent1->member as $parent2)
                                    <optgroup label="└― {{$parent2->name}}">
                                        @foreach($parent2->member as $class)
                                            <option value="{{$class->id}}" @if($obj->position == $class->id) selected @endif>&emsp;└―└― {{$class->name}}</option>
                                        @endforeach
                                    </optgroup>
                                @endforeach
                            </optgroup>
                        @endforeach
                    </select>
                @else
                    <div class="layui-input layui-bg-gray">
                        @foreach($position_class as $parent1)
                            @foreach($parent1->member as $parent2)
                                @foreach($parent2->member as $class)
                                    @if($obj->position == $class->id)
                                        {{$class->name}}
                                    @endif
                                @endforeach
                            @endforeach
                        @endforeach
                    </div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>求职状态</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <select id="state" name="state">
                        <option value="0" disabled selected>请选择</option>
                        @foreach($working_state as $k => $v)
                            <option value="{{$k}}" @if($obj->state == $k) selected @endif>{{$v['name']}}</option>
                        @endforeach
                    </select>
                @else
                    <div class="layui-input layui-bg-gray">
                        @foreach($working_state as $k => $v)
                            @if($obj->state == $k)
                                {{$v['name']}}
                            @endif
                        @endforeach
                    </div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>期待国家</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <select id="country" name="country" lay-search>
                        <option value="0" disabled selected>请选择</option>
                        @foreach($country as $k => $v)
                            <option value="{{$k}}" @if($obj->country == $k) selected @endif>{{$v['name']}}</option>
                        @endforeach
                    </select>
                @else
                    <div class="layui-input layui-bg-gray">
                        @foreach($country as $k => $v)
                            @if($obj->country == $k)
                                {{$v['name']}}
                            @endif
                        @endforeach
                    </div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>期待月薪</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <select id="salary" name="salary">
                        <option value="0" disabled selected>请选择</option>
                        @foreach($working_salary as $k => $v)
                            <option value="{{$k}}" @if($obj->salary == $k) selected @endif>{{$v['name']}}</option>
                        @endforeach
                    </select>
                @else
                    <div class="layui-input layui-bg-gray">
                        @foreach($working_salary as $k => $v)
                            @if($obj->salary == $k)
                                {{$v['name']}}
                            @endif
                        @endforeach
                    </div>
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>到岗时间</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <select id="coming" name="coming">
                        <option value="0" disabled selected>请选择</option>
                        @foreach($arrival_time as $k => $v)
                            <option value="{{$k}}" @if($obj->coming == $k) selected @endif>{{$v['name']}}</option>
                        @endforeach
                    </select>
                @else
                    <div class="layui-input layui-bg-gray">
                        @foreach($arrival_time as $k => $v)
                            @if($obj->coming == $k)
                                {{$v['name']}}
                            @endif
                        @endforeach
                    </div>
                @endif
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">一句话介绍</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <textarea name="brief" placeholder="请输入内容" lay-verify="required" class="layui-textarea">{{$obj->brief}}</textarea>
                @else
                    <div class="layui-textarea layui-bg-gray"><pre>{{$obj->brief}}</pre></div>
                @endif
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>简历附件</label>
            <div class="layui-input-block">
                @if(Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->uid)
                    <button type="button" class="layui-btn" id="file_button"><i class="layui-icon"></i>上传简历附件</button>
                    @if(Auth::id()==$obj->uid)
                        <div class="layui-input layui-bg-gray" id="file_preview">@if($obj->file)<a href="{{route('resume_download',$obj->id)}}" class="check-btn" target="_blank">{{$obj->file?$obj->file->name:'未命名'}}</a>@endif</div>
                    @else
                        <span class="layui-word-aux" id="file_preview">{{$obj->file?$obj->file->name:''}}</span>
                    @endif
                    <input type="hidden" name="file_id" id="file_id" value="{{$obj->file?$obj->file->id:''}}">

                @else
                    @if($obj->display)
                        <div class="layui-input layui-bg-gray">@if($obj->file)<a href="{{route('resume_download',$obj->id)}}" class="check-btn" target="_blank">{{$obj->file?$obj->file->name:'未命名'}}</a>@endif</div>
                    @else
                        @if(Auth::user()->type != 1)
                            <div class="layui-input layui-bg-gray">********</div>
                        @else
                            <div class="layui-input layui-bg-gray"><a href="javascript:;" onclick="buy('{{route('resume_buy',$obj->id)}}')">********</a></div>
                        @endif
                    @endif
                @endif
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建人</label>
            <div class="layui-input-block">
                <div class="layui-input layui-bg-gray">{{$obj->user?$obj->user->username:'快速投递'}}</div>
            </div>
        </div>
        @if((Auth::user()->hasAnyRole(['admin']) || Auth::id()==$obj->assign || $obj->share) && Auth::user()->type == 1)
            <div class="layui-form-item">
                <label class="layui-form-label">指定任务归属于</label>
                <div class="layui-input-block">
                    <label for="shareTo">
                        <input type="radio" lay-filter="shareTo" id="shareTo1" name="shareTo" value="1" title="私有" @if($obj->shareTo == 1) checked @endif>
                    </label>
                    @if(Auth::user()->type == 1)
                    <label for="shareTo">
                        <input type="radio" lay-filter="shareTo" id="shareTo2" name="shareTo" value="2"  title="共享全员" @if($obj->shareTo == 2) checked @endif>
                    </label>
                    <label for="shareTo" class="no-margin">
                        <input type="radio" lay-filter="shareTo" id="shareTo3" name="shareTo" title="指派给" value="3" @if($obj->shareTo == 3) checked @endif>
                        <div class="layui-inline">
                            <div class="layui-input-inline" style="width: 160px;">
                                <select lay-filter="assign" id="assign" name="assign">
                                    <option value="0" disabled @if($obj->share || $obj->shareTo == 1 || $obj->shareTo == 2) selected @endif>请选择</option>
                                    @foreach($frame as $item)
                                        @foreach($item as $leader)
                                            <optgroup label="{{$leader->user->username}}">
                                                <option value="{{$leader->uid}}" @if($obj->assign == $leader->uid) selected @endif>{{$leader->user->username}}</option>
                                                @foreach($leader->member as $v)
                                                    <option value="{{$v->uid}}" @if($obj->assign == $v->uid) selected @endif>{{$v->user->username}}</option>
                                                @endforeach
                                            </optgroup>
                                        @endforeach
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-mid layui-word-aux fs12">（若简历{{$resume_day}}天内未开发成功签约会自动变为共享，供其他人可再二次开发)</div>
                    </label>
                    @endif
                </div>
            </div>
        @else
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                    <div class="layui-form-mid layui-word-aux fs12">（本系统将为各位合作伙伴持续保存上传简历{{$resume_out_day}}天，超过{{$resume_out_day}}天的信息会定期清理避免数据冗余，请知悉)</div>
            </div>
        @endif
    </form>
</div>
@section('footer')
    <script>
        var obj = @JSON($obj);
        
        layui.use(['laydate','form'], function(){
            var laydate = layui.laydate;
            var form = layui.form;

            form.on('radio(shareTo)', function(data){
                if (data.value == 1 || data.value == 3){
                    if (obj.display){
                        if (data.value == 1){
                            form.val("form-user", {
                                "assign": 0,
                            });
                        }
                    }else{
                        buy('{{route('resume_buy',$obj->id)}}');
                        $("input[name='shareTo']").each(function() {
                            if ($(this).attr('value') == obj.shareTo) {
                                $(this).attr('checked','checked').prop("checked",true);
                            }else{
                                $(this).removeAttr('checked');
                            }
                        });
                        form.val("form-user", {
                            "assign": 0,
                        });
                        form.render();
                    }
                }else if (data.value == 2){
                    form.val("form-user", {
                        "assign": 0,
                    });
                }
            });

            form.on('select(assign)', function(data){
                if (data.value){
                    if (obj.display){
                        $("input[name='shareTo']").each(function() {
                            $(this).removeAttr('checked');
                        });
                        $("#shareTo3").attr('checked','checked').prop("checked",true);
                        form.render(); //更新全部
                    }else{
                        buy('{{route('resume_buy',$obj->id)}}');
                        $("input[name='shareTo']").each(function() {
                            if ($(this).attr('value') == obj.shareTo) {
                                $(this).attr('checked','checked').prop("checked",true);
                            }else{
                                $(this).removeAttr('checked');
                            }
                        });
                        form.val("form-user", {
                            "assign": 0,
                        });
                        form.render();
                    }
                }
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#birthday', //指定元素
                type: 'month'
            });
        });

        function buy(url) {
            if (obj.assign=='') {
                layer.confirm("你确定购买吗？此操作不能撤销！(您当前拥有 {{Auth::user()->download}} 下载点，本次下载将消耗 1 下载点)", {icon: 3, title:'提示'},
                    function(index){//确定回调
                        $.ajax({
                            type: 'get',
                            url: url,
                            dataType: 'json',
                            success: function(data){
                                if(data.code){
                                    window.location.reload();
                                    layer.close(index);
                                }else{
                                    layer.msg(data.msg,{icon: 5,time:1000});
                                }
                            },
                            error:function() {
                                layer.msg('服务器错误!',{icon: 5,time:1000});
                            }
                        });
                    },function (index) {//取消回调
                        layer.close(index);
                    }
                );
            }else{
                layer.msg('该简历归属于'+obj.assign_user.username+'，无法下载！如有需要，请沟通简历归属人',{icon: 5,time:1000});
            }

        }
    </script>
@endsection
@include('Home.User.Common._footer')
@include('Home.User.Common._form')